package com.contextor.magiccards.web.handlers;

import com.contextor.magiccards.model.BaseBean;
import com.contextor.magiccards.model.errors.MagicCardsException;
import com.contextor.magiccards.model.errors.args.IllegalUserAccessException;
import com.contextor.magiccards.model.errors.args.InvalidArgumentException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * User: Sergey
 * Date: 02.04.2011 13:49:39
 */
public abstract class AbstractTOHandler {
    Logger logger = LoggerFactory.getLogger(getClass());

    public boolean checkUid(String uid) throws MagicCardsException {
        if (uid == null) {
            throw new MagicCardsException("uid=" + uid);
        }
        return true;
    }

    public boolean compareUids(String uid, BaseBean entity) throws MagicCardsException {
        if (uid == null || entity == null) {
            throw new InvalidArgumentException("Input parameter is null;");
        }
        if (!uid.equals(entity.getUid())) {
            throw new IllegalUserAccessException("The entity doesn't belong to user; uid=" + uid + " entity uid=" + entity.getUid());
        }
        return true;
    }

}
